﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace InfoWykaz
{
    public partial class Options : Form
    {
        public Options()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.user.Text.Length > 0)
            {
                if (this.password.Text.Length > 0)
                {
                    if (this.dataBase.Text.Length > 0)
                    {
                        Serialize.SerializeToXml(new OptionsValue
                        {
                            dataBase = this.dataBase.Text,
                            password = this.password.Text,
                            user = this.user.Text
                        }, new System.IO.FileInfo("config.xml"));
                        this.Close();
                    }
                    else MessageBox.Show("Podaj nazwę bazy danych!");
                }
                else MessageBox.Show("Podaj hasło!");
            }
            else MessageBox.Show("Podaj nazwę użytkownika!");
        }

        private void Options_Load(object sender, EventArgs e)
        {
            FileInfo f = new FileInfo("config.xml");
            if (f.Exists)
            {
                OptionsValue options = Serialize.DeserializeFromXml(f);
                this.user.Text = options.user;
                this.password.Text = options.password;
                this.dataBase.Text = options.dataBase;
            }
        }
    }
}
